package com.cll.learn.control.demo04;

import java.util.Random;
import java.util.concurrent.Phaser;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2021/5/15 18:02
 */
public class AwaitThread implements Runnable {

    private final Phaser phaser;

    public AwaitThread(Phaser phaser) {
        this.phaser = phaser;
    }

    @Override
    public void run() {
        System.out.println(phaser.getArrivedParties() + "线程" + Thread.currentThread().getName() + "开始执行");
        try {
            Thread.sleep(Math.abs(new Random().nextInt(1000)));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 表明到达了
        phaser.arrive();
        System.out.println(phaser.getArrivedParties() + "线程" + Thread.currentThread().getName() + "执行完成");
    }
}
